<template>
  <div>
  <van-sticky style="background-color: white">
    <van-nav-bar
      title="收货地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
  </van-sticky>
  <!--   v-for="(item,index) in detailsList" -->
    <div >
      <van-address-list
        v-model="chosenAddressId"
        :list="addressList"

        default-tag-text="默认"

        @add="onAdd"
        @edit="onEdit"
      />
    </div>

  </div>
</template>

<script>
export default {
  name: "address",
  data(){
    return {
      consignee: sessionStorage.getItem("consignee"),
      chosenAddressId: " ",
      addressList: [],
    }
  },
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    onAdd() {
      this.$router.push("/addAddress");
    },
    //点击编辑传地址id给地址编辑，以便地址回显
    onEdit(item, index) {
      let id = this.list[index].id;
      this.$router.push(`editAddress?id=${id}`);
    },
    jump(path) {
      this.$router.push(path)
    },
    jumpToDetail(id) {
      console.log(id)
      this.$router.push("/ediAddress/" + id)
    },
    onLoad() {
      setTimeout(() => {
        if (this.refreshing) {
          //这里也是转换，是在前端转
          // this.addressList = [
          //   {
          //     id: 'id',
          //     name: 'consignee',
          //     tel: 'phone',
          //     address: 'detail',
          //     isDefault: true,
          //   },
          // ];
          // this.refreshing = false;
        }
        console.log(this.addressList)
      }, 1000);
    },

    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    }
  },
  created() {
    let _this = this
    this.$axios.get("/address/allAddressByUser").then((resp)=>{
      console.log("获取返回值：",resp.data.data.addressList)
      _this.addressList = resp.data.data.addressList

    })
  },
}
</script>

<style scoped>

</style>
